package com.ebelter.seneo.models;




import com.ebelter.btcomlib.models.bluetooth.products.nb.BondDevices;
import com.ebelter.btcomlib.models.bluetooth.products.nb.BondDevices_Table;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord_Table;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserMeasureUploadData;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserMeasureUploadData_Table;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos_Table;
import com.raizlabs.android.dbflow.sql.language.Delete;
import com.raizlabs.android.dbflow.sql.language.Method;
import com.raizlabs.android.dbflow.sql.language.Select;

import java.util.List;


public class SeneoDbUtils {


    // DbUtils.deleteTable(BondDevices.class);
    public static void deleteTable(Class clz){
        Delete.table(clz);//删除整张表
    }


    public static SeneoUserinfos getHostUserinfos(){
        List<SeneoUserinfos> r = new Select().from(SeneoUserinfos.class).queryList();
        if (r.size()>0){
            long hostid = r.get(0).host_id;
            SeneoUserinfos r2 = new Select().from(SeneoUserinfos.class).where(SeneoUserinfos_Table.user_id.eq(hostid)).querySingle();
            return r2;
        }
        return null;
    }

    public static long getHostId(){
        List<SeneoUserinfos> r = new Select().from(SeneoUserinfos.class).queryList();
        if (r.size()>0){
            long hostid = r.get(0).host_id;
          //  SeneoUserinfos r2 = new Select().from(SeneoUserinfos.class).where(SeneoUserinfos_Table.user_id.eq(hostid)).querySingle();
            return hostid;
        }
        return -1;
    }

    //获取用户信息
    public static SeneoUserinfos getUserinfos(long userid){
        SeneoUserinfos r2 = new Select().from(SeneoUserinfos.class).where(SeneoUserinfos_Table.user_id.eq(userid)).querySingle();
        return r2;
    }



    public static  List<SeneoUserMeasureUploadData> getSeneoUserMeasureUploadData(long userid){
        List<SeneoUserMeasureUploadData> r2 = new Select().from(SeneoUserMeasureUploadData.class).where(SeneoUserMeasureUploadData_Table.user_id.eq(userid)).queryList();
        return r2;
    }
    //获取所有用户信息
    public static List<SeneoUserinfos> getAllUserinfos(){
        List<SeneoUserinfos> r = new Select().from(SeneoUserinfos.class).queryList();
        return r;
    }


    //获取用户信息
    public static SeneoUserCurrentMeasureRecord getSeneoUserCurrentMeasureRecord(long hostid, long userid){
        SeneoUserCurrentMeasureRecord r2 = new Select().from(SeneoUserCurrentMeasureRecord.class)
                .where(SeneoUserCurrentMeasureRecord_Table.host_id.eq(hostid))
                .and(SeneoUserCurrentMeasureRecord_Table.user_id.eq(userid))
                .querySingle();
        return r2;
    }

    public static SeneoUserMeasureUploadData getSeneoUserMeasureUploadData(){
        return new Select().from(SeneoUserMeasureUploadData.class).querySingle();
    }


}
